<template>
  <div style="display: none">
    <div
      v-show="showAudit || auditList.length"
      class="slot-component right-sidebar"
      :class="className"
    >
      <ul class="nav"></ul>
      <div class="content">
        <template v-if="showAudit">
          <div class="title">审核</div>
          <el-form
            ref="ruleForm"
            :model="ruleForm"
            label-width="80px"
            size="small"
          >
            <el-form-item
              label="结论"
              :rules="{
                required: true,
                message: '请选择是否通过',
                trigger: 'blur',
              }"
            >
              <el-radio-group v-model="ruleForm.pass">
                <el-radio :label="true">通过</el-radio>
                <el-radio :label="false">驳回</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              label="意见"
              :rules="{
                max: 100,
                message: '长度不超过100个字符',
                trigger: 'blur',
              }"
            >
              <el-input
                type="textarea"
                v-model="ruleForm.remark"
                maxlength="100"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit">提交</el-button>
              <el-button>取消</el-button>
            </el-form-item>
          </el-form>
        </template>

        <template v-if="auditList.length">
          <div class="title">审核记录</div>
          <el-timeline>
            <el-timeline-item
              v-for="(item, index) in auditList"
              :key="index"
              :color="item.color"
            >
              <div>{{ item.auditorName }} {{ item.recordTime }}</div>
              <div>
                审核结果：<el-tag v-if="item.status === '4'" type="danger"
                  >驳回</el-tag
                ><el-tag v-else type="success">通过</el-tag>
              </div>
              <div>审核意见：{{ item.remark }}</div>
            </el-timeline-item>
          </el-timeline>
        </template>
      </div>
      <div class="collapse" @click="toggleCollapse">
        <i :class="iconClass"></i>
      </div>
    </div>
  </div>
</template>

<script>
import { Message } from "element-ui";
import { submitAudit, getAuditInfoList } from "@/api/business";

export default {
  data() {
    return {
      collapse: false,
      ruleForm: {
        pass: undefined,
        remark: "",
      },
      showAudit: false,
      auditList: [],
    };
  },
  computed: {
    className() {
      return this.collapse ? " collapse" : "";
    },
    iconClass() {
      return this.collapse ? "el-icon-arrow-left" : "el-icon-arrow-right";
    },
  },
  methods: {
    toggleCollapse() {
      this.collapse = !this.collapse;
    },
    async getList() {
      const res = await getAuditInfoList({
        auditId: this.$route.query.audit || "",
        docNo: this.$route.query.docNo,
      });
      this.showAudit = res?.data?.showAudit;
      this.auditList = res?.data?.list?.map((i) => {
        let color = "";
        if (i.status === "4") {
          color = "#F56C6C";
        } else if (i.status === "3") {
          color = "#67C23A";
        }
        return { ...i, color };
      });
    },
    async onSubmit() {
      if (this.ruleForm.pass === undefined) {
        return Message.warning("请选择是否通过");
      }
      if (this.ruleForm.remark.length > 100) {
        return Message.warning("长度不超过100个字符");
      }
      try {
        await submitAudit({ id: this.$route.query.audit, ...this.ruleForm });
        Message.success("提交成功");
        this.getList();
      } catch (error) {
        console.debug(error);
      }
    },
  },
  mounted() {
    const { editContentType, entry } = this.$route.query;
    if (editContentType !== 'document' || entry) {
      console.debug('不显示审核功能')
      return
    }
    this.getList();
  },
};
</script>
<style scoped>
@import url("./iconfont/iconfont.css");
.title {
  padding: 20px 0 0 24px;
  font-size: 18px;
  font-weight: bold;
}
.slot-component .el-button {
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: #ffffff;
  border: 1px solid #dcdfe6;
  border-color: #dcdfe6;
  color: #606266;
  text-align: center;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  -webkit-transition: 0.1s;
  transition: 0.1s;
  font-weight: 400;
  user-select: none;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
}
.slot-component .el-button--small {
  padding: 9px 15px;
  font-size: 12px;
  border-radius: 3px;
}
.slot-component .el-button--primary {
  color: #ffffff;
  background-color: #1890ff;
}

.slot-component .el-button + .el-button {
  margin-left: 10px;
}

.slot-component .el-form-item:after,
.slot-component .el-form-item:before {
  display: table;
  content: "";
}
.slot-component .el-form-item--small.el-form-item {
  margin-bottom: 0;
}
.slot-component .el-radio-group {
  display: inline-block;
  line-height: 1;
  vertical-align: middle;
  font-size: 0;
}
.slot-component .el-radio {
  color: #606266;
  font-weight: 500;
  line-height: 1;
  position: relative;
  cursor: pointer;
  display: inline-block;
  white-space: nowrap;
  outline: none;
  font-size: 14px;
  margin-right: 30px;
  user-select: none;
}
.slot-component .el-radio__input {
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  display: inline-block;
  line-height: 1;
  position: relative;
  vertical-align: middle;
}
.slot-component ::v-deep .el-radio__inner {
  border: 1px solid #dcdfe6;
  border-radius: 100%;
  width: 14px;
  height: 14px;
  background-color: #ffffff;
  position: relative;
  cursor: pointer;
  display: inline-block;
  box-sizing: border-box;
}
.slot-component ::v-deep .el-radio__input.is-checked .el-radio__inner {
  border-color: #1890ff;
  background: #1890ff;
}
.slot-component ::v-deep .el-radio__original {
  opacity: 0;
  outline: none;
  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
}
.slot-component ::v-deep .el-radio__label {
  font-size: 14px;
  padding-left: 10px;
}

.slot-component ::v-deep .el-form-item__label {
  text-align: right;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 0;
  box-sizing: border-box;
}

.slot-component ::v-deep .el-textarea__inner {
  display: block;
  resize: vertical;
  padding: 5px 15px;
  line-height: 1.5;
  box-sizing: border-box;
  width: 100%;
  font-size: inherit;
  color: #606266;
  background-color: #ffffff;
  background-image: none;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.slot-component .el-timeline {
  padding: 20px 0 0 30px;
}

.slot-component .el-timeline {
  margin: 0;
  font-size: 14px;
  list-style: none;
}

.slot-component .el-timeline-item {
  position: relative;
  padding-bottom: 20px;
}

.slot-component ::v-deep .el-timeline-item__tail {
  position: absolute;
  left: 4px;
  height: 100%;
  border-left: 2px solid #e4e7ed;
}

.slot-component ::v-deep .el-timeline-item__wrapper {
  position: relative;
  padding-left: 28px;
  top: -3px;
}

.slot-component ::v-deep .el-timeline-item__node--primary {
  background-color: #409eff;
}

.slot-component ::v-deep .el-timeline-item__icon {
  color: #fff;
  font-size: 13px;
}

.slot-component ::v-deep .el-timeline-item__content {
  color: #303133;
}

.slot-component ::v-deep .el-timeline-item__timestamp {
  color: #909399;
  line-height: 1;
  font-size: 13px;
}

.slot-component ::v-deep .el-timeline-item__timestamp.is-bottom {
  margin-top: 8px;
}

.slot-component ::v-deep .el-timeline-item__node {
  position: absolute;
  background-color: #e4e7ed;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.slot-component ::v-deep .el-timeline-item__node--normal {
  left: -1px;
  width: 12px;
  height: 12px;
}

.slot-component .el-tag {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid #d9ecff;
  border-radius: 4px;
  box-sizing: border-box;
  white-space: nowrap;
}

.slot-component.collapse {
  width: 40px;
}
.slot-component {
  width: 350px;
  position: relative;
  transition: all 0.25s;
  display: flex;
  background-color: #f3f3f3;
  border-right: 1px solid #ccc;
}

.slot-component ul.nav {
  list-style-type: none;
  border-right: 1px solid #ccc;
  width: 40px;
  font-size: 12px;
  padding: 7px 0;
  text-align: center;
  cursor: pointer;
}

.slot-component .content {
  flex: 1;
  min-width: calc(100% - 41px);
  background-image: linear-gradient(0deg, #eee, #fff);
  position: relative;
  transition: width 0.5s;
}

.slot-component .content > div {
  width: 100%;
  position: relative;
  overflow: auto;
}

.slot-component .collapse {
  padding: 3px 0;
  cursor: pointer;
  position: absolute;
  left: 14px;
  bottom: 20px;
  z-index: 100;
  border-top-right-radius: 3px;
  border-bottom-right-radius: 3px;
  width: 12px;
  text-align: center;
  height: 18px;
  display: flex;
}

.slot-component .collapse > i {
  font-size: 20px;
}
</style>
